home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / Smooth Updates / source / smupcdev.c next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  1.6 KB  |  70 lines  |  [TEXT/KAHL]

  1. /*
  2.  * smupcdev.c
  3.  * 17 June 1993 by Mark C Smith • University of Michigan
  4.  * Copyright (c) 1993 Mark C Smith
  5.  */
  6. #include <Dialogs.h>
  7. #include <Devices.h>
  8. #include <Memory.h>
  9. #include <GestaltEqu.h>
  10. #include "smupdate.h"
  11.  
  12. pascal long main( short msg, short item, short numitems, short id, EventRecord *erp,
  13.                         long value, DialogPtr dlp );
  14.  
  15.  
  16. typedef struct {
  17.     Boolean            smst_on;
  18.     GestaltProcPtr    smst_gestproc;
  19. } smstatus;
  20.  
  21.  
  22. pascal long
  23. main( short msg, short item, short numitems, short id, EventRecord *erp,
  24.         long value, DialogPtr dlp )
  25. {
  26.     short        type;
  27.     Handle        hdl;
  28.     Rect        r;
  29.     long        response;
  30.     smstatus    **smsth;
  31.  
  32.     smsth = (smstatus **)value;
  33.  
  34.     switch ( msg ) {
  35.     case initDev:
  36.         /*
  37.          * make sure we can talk to our patch
  38.          */
  39.         if ( Gestalt( sSmUpdate, &response ) != noErr ) {
  40.             return( cdevGenErr );    /* XXX lame error return */
  41.         }
  42.         if (( smsth = (smstatus **)NewHandle( sizeof( smstatus ))) == NULL ) {
  43.             return( cdevMemErr );
  44.         }
  45.         (*smsth)->smst_gestproc = (GestaltProcPtr)response;
  46.         ((*smsth)->smst_gestproc)( sSmStatus, &response );
  47.         (*smsth)->smst_on = ( response != 0 );
  48.  
  49.         if ( (*smsth)->smst_on ) {
  50.             GetDItem( dlp, numitems + 1, &type, &hdl, &r );
  51.             SetCtlValue( (ControlHandle)hdl, 1 );
  52.         }
  53.         value = (long)smsth;
  54.         break;
  55.     case closeDev:
  56.         DisposeHandle( (Handle)value );
  57.         break;
  58.     case hitDev:
  59.         if ( item == numitems + 1 ) {
  60.             GetDItem( dlp, item, &type, &hdl, &r );
  61.             ((*smsth)->smst_gestproc)( (*smsth)->smst_on ? sSmOff : sSmOn, &response );
  62.             (*smsth)->smst_on = !(*smsth)->smst_on;
  63.             SetCtlValue( (ControlHandle)hdl, 1 - GetCtlValue( (ControlHandle)hdl ));
  64.         }
  65.         break;
  66.     }
  67.  
  68.     return( value );
  69. }
  70.